package com.shaoshaohuo.app.adapter;

import java.util.List;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.entity.News;
import com.shaoshaohuo.app.utils.ImageLoadUtil;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class NewsAdapter<T> extends MyBaseAdapter<News> {

	public NewsAdapter(Context ctx, List<News> list, boolean flag) {
		super(ctx, list, flag);
	}

	@Override
	public View getView(int pos, View convertView, ViewGroup group) {
		
		ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(context,R.layout.view_news_item, null);
            holder = new ViewHolder();
            holder.titleText = (TextView) convertView.findViewById(R.id.textview_title);
            holder.contentText = (TextView) convertView.findViewById(R.id.textview_content);
            holder.timeText = (TextView) convertView.findViewById(R.id.textview_time);
            holder.newsImage = (ImageView) convertView.findViewById(R.id.imageview_image);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
		
        News item = list.get(pos);
        
        ImageLoader.getInstance().displayImage(item.getImg(), holder.newsImage, ImageLoadUtil.build);
        holder.titleText.setText(item.getTitle());
        holder.timeText.setText(item.getSource()+"  "+item.getCtime());
        holder.contentText.setText(item.getSummary());
        
		return convertView;
	}
	
	static class ViewHolder{
		TextView titleText;
		TextView contentText;
		TextView timeText;
		
		ImageView newsImage;
	}
	
}
